import { ref } from 'vue'
import type PageModal from '@/components/page-modal/page-modal.vue'
type callbackFnType = (data?: any) => void

function usePageModal(
  newCallback?: callbackFnType,
  editCallBack?: callbackFnType
) {
  const modalRef = ref<InstanceType<typeof PageModal>>()
  function handleNewClick() {
    modalRef.value?.setModalVisible()

    // 调用回调函数，在编辑之后点击新建时，取消勾选

    if (newCallback) newCallback()
  }
  function handleEditClick(itemData: any) {
    modalRef.value?.setModalVisible(false, itemData)
    if (editCallBack) editCallBack(itemData)
  }

  return { modalRef, handleNewClick, handleEditClick }
}
export default usePageModal
